import { getChannelList, getAllChannelList } from '@/api/channel'

export default {
  namespaced: true,
  state: {
    channelList: [],
    allChannelList: []
  },
  mutations: {
    setChannelList(state, data) {
      state.channelList = data
    },
    setAllChannelList(state, data) {
      state.allChannelList = data
    },
    addchannelList(state, channel) {
      state.channelList.push(channel)
    },
    delChannelList(state, id) {
      state.channelList = state.channelList.filter(item => item.id !== id)
    }

  },
  actions: {
    async getChannelList(context) {
      const res = await getChannelList()
      context.commit('setChannelList', res.data.channels)
    },
    async getAllChannelList(context) {
      const res = await getAllChannelList()
      context.commit('setAllChannelList', res.data.channels)
    }
  },
  getters: {
    optionalChannelList(state) {
      return state.allChannelList.filter(item => state.channelList.findIndex(v => v.id === item.id) === -1)
    }
  }
}
